﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using IterationLife.Extensions.Dtos;
using IterationLife.FootballTeaching.Enums;
using IterationLife.FootballTeaching.ItemModels;
using Util;
using Util.Applications;

namespace IterationLife.PlatformBackEnd.AppServices.Dtos.FootballTeachings
{
    /// <summary>
    /// 课程数据传输对象
    /// </summary>
    [DataContract]
    public class CourseDto : DtoBase
    {

        /// <summary>
        /// 初始化课程数据传输对象
        /// </summary>
        public CourseDto()
        {
            CourseCategories = new CourseCategories();
            PlayerPositions = new PlayerPositions();
            Banner = new Resources();
        }

        /// <summary>
        /// 课程分类集合
        /// </summary>
        [Required(ErrorMessage = "课程分类集合不能为空")]
        [Display(Name = "课程分类集合")]
        [DataMember]
        public CourseCategories CourseCategories { get; set; }

        /// <summary>
        /// 课程分类
        /// </summary>
        [Display(Name = "课程分类")]
        [DataMember]
        public string CourseCategoryNames => CourseCategories.Select(t => t.Name).Join();

        /// <summary>
        /// 球员位置集合
        /// </summary>
        [Required(ErrorMessage = "球员位置集合不能为空")]
        [Display(Name = "球员位置集合")]
        [DataMember]
        public PlayerPositions PlayerPositions { get; set; }

        /// <summary>
        /// 球员位置
        /// </summary>
        [Display(Name = "球员位置")]
        [DataMember]
        public string PlayerPositionNames => PlayerPositions.Select(t => t.Name).Join();

        /// <summary>
        /// 名称
        /// </summary>
        [Required(ErrorMessage = "名称不能为空")]
        [StringLength(50, ErrorMessage = "名称输入过长，不能超过50位")]
        [Display(Name = "名称")]
        [DataMember]
        public string Name { get; set; }

        /// <summary>
        /// 封面图
        /// </summary>
        [Required(ErrorMessage = "封面图不能为空")]
        [Display(Name = "封面图")]
        [DataMember]
        public Resources Banner { get; set; }

        /// <summary>
        /// 难度
        /// </summary>
        [Required(ErrorMessage = "难度不能为空")]
        [Display(Name = "难度")]
        [DataMember]
        public DifficultyType? Difficulty { get; set; }

        /// <summary>
        /// 动作数
        /// </summary>
        [Required(ErrorMessage = "动作数不能为空")]
        [Display(Name = "动作数")]
        [DataMember]
        public int ActionNumber { get; set; }

        /// <summary>
        /// 参与人数
        /// </summary>
        [Required(ErrorMessage = "参与人数不能为空")]
        [Display(Name = "参与人数")]
        [DataMember]
        public long ParticipationNumber { get; set; }

        /// <summary>
        /// 排序号
        /// </summary>
        [Display(Name = "排序号")]
        [DataMember]
        public int? SortId { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [Display(Name = "创建时间")]
        [DataMember]
        public DateTime? CreationTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        [Display(Name = "创建人")]
        [DataMember]
        public Guid? CreatorId { get; set; }

        /// <summary>
        /// 最后修改时间
        /// </summary>
        [Display(Name = "最后修改时间")]
        [DataMember]
        public DateTime? LastModificationTime { get; set; }

        /// <summary>
        /// 最后修改人
        /// </summary>
        [Display(Name = "最后修改人")]
        [DataMember]
        public Guid? LastModifierId { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        [Required(ErrorMessage = "是否删除不能为空")]
        [Display(Name = "是否删除")]
        [DataMember]
        public bool IsDeleted { get; set; }

        /// <summary>
        /// 版本号
        /// </summary>
        [Display(Name = "版本号")]
        [DataMember]
        public Byte[] Version { get; set; }

        /// <summary>
        /// 输出课程状态
        /// </summary>
        public override string ToString()
        {
            return this.ToEntity().ToString();
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="sortId">排序号</param>
        public CourseDto Init(int sortId)
        {
            Difficulty = DifficultyType.OneLevel;
            SortId = sortId;
            return this;
        }
    }
}
